package cn.billy.controller;

import cn.billy.User;
import cn.billy.handler.UserHandler;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.sun.deploy.security.BlockedException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope // 实时监控
public class UserController {
    @Value("${test}")
    private Long test;

    @GetMapping("/getByUserId/{id}")
    @SentinelResource(value = "getByUserId", blockHandler = "getUserByIdBlockHandler", blockHandlerClass = UserHandler.class,fallback = "fallback")
    public User getById(@PathVariable Long id){
        int i = 1/0;
        return User.builder().id(id).name("李某").intro("不管嘛").build();
    }

    public User fallback(@PathVariable Long id){
        return User.builder().id(-2l).name("降级").intro("降级").build();
    }
}
